﻿Imports EntidadNegocios
Imports System.Data.SqlClient

Public Class CierreComedorAD



    Private conn As SqlConnection
    Private comando As New SqlCommand

    Public Sub New()
        Dim objConexion As New conexion
        conn = objConexion.abrir
        comando.Connection = conn

    End Sub


    Public Sub agregar(ByVal objCierre As CierreComedorEN)


        comando.CommandType = CommandType.StoredProcedure
        comando.CommandText = "sp_insertarCierre"


        Dim pFecha As New SqlParameter("@fecha", SqlDbType.DateTime)
        pFecha.Value = objCierre.fecha
        pFecha.Direction = ParameterDirection.Input
        comando.Parameters.Add(pFecha)

        Dim pTurno As New SqlParameter("@turno", SqlDbType.Int)
        pTurno.Value = objCierre.turno
        pTurno.Direction = ParameterDirection.Input
        comando.Parameters.Add(pTurno)

        Dim pMonto As New SqlParameter("@monto", SqlDbType.Float)
        pMonto.Value = objCierre.montoTotal
        pMonto.Direction = ParameterDirection.Input
        comando.Parameters.Add(pMonto)

        Dim pId As New SqlParameter("@id", SqlDbType.Int)
        pId.Value = objCierre.idCobrador
        pId.Direction = ParameterDirection.Input
        comando.Parameters.Add(pId)


        comando.ExecuteNonQuery()
        comando.Parameters.Clear()






    End Sub

    Public Function obtenerUltimoCierre() As CierreComedorEN

        Dim reader As SqlDataReader
        Dim objCierre As New CierreComedorEN

        comando.CommandType = CommandType.Text
        comando.CommandText = " select max(idCierre) from CierreComedor"
        reader = comando.ExecuteReader


        If reader.HasRows Then

            While reader.Read

                objCierre.idCierre = reader(0)


            End While


        End If

        reader.Close()


        Return objCierre



    End Function



End Class
